
package controller;

import dao.EmpleadoDao;
import entity.Empleado;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@WebServlet(name = "EmpleadoServlets", 
        urlPatterns = {"/Consulta"})
public class EmpleadoServlets extends HttpServlet {

   @Override
    protected void service(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
       String alias=request.getServletPath();
       if (alias.equals("/Consulta")) {
           ConsultarSueldo(request,response);
      }
    }

    private void ConsultarSueldo(HttpServletRequest request, HttpServletResponse response)
                    throws IOException {
        response.setContentType("text/html");
        PrintWriter out = response.getWriter();
        try {
            String cod=request.getParameter("codigo");
            EmpleadoDao obj=new EmpleadoDao();
            Empleado datos=obj.dameUnEmpleado(Integer.parseInt(cod));
            out.println("Id Empleado     :" + datos.getIdempleado()+"<br>");
            out.println("Nombre          :" + datos.getNombre()+"<br>");
            out.println("Apellido        :" + datos.getApellido()+"<br>");
            out.println("Id departamento :" + datos.getIddepartamento()+"<br>");
            out.println("Sueldo          :" + datos.getSueldo()+"<br>");
        } catch (Exception e) {
            out.println("Error :" + e.getMessage());
        }finally{
            out.flush();
            out.close();
        }
    }

}

